/**
 * output package name
 */
package com.kingdee.eas.custom.bscc.report.client;

import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Window;
import java.awt.event.*;

import javax.swing.SwingUtilities;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.bos.ctrl.kdf.table.KDTable;
import com.kingdee.bos.ctrl.kdf.table.event.KDTDataRequestEvent;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.eas.base.commonquery.client.CustomerQueryPanel;
import com.kingdee.eas.base.permission.client.longtime.ILongTimeTask;
import com.kingdee.eas.base.permission.client.longtime.LongTimeDialog;
import com.kingdee.eas.custom.bscc.report.ProjectGkgFacadeFactory;
import com.kingdee.eas.framework.*;
import com.kingdee.eas.framework.config.TablePreferencesHelper;
import com.kingdee.eas.framework.report.ICommRptBase;
import com.kingdee.eas.framework.report.client.CommRptBaseConditionUI;
import com.kingdee.eas.framework.report.util.KDTableUtil;
import com.kingdee.eas.framework.report.util.RptParams;
import com.kingdee.eas.framework.report.util.RptRowSet;
import com.kingdee.eas.framework.report.util.RptTableHeader;
import com.kingdee.eas.xr.helper.TableUtils;

/**
 * output class name
 */
public class ProjectGkgUI extends AbstractProjectGkgUI
{
    private static final Logger logger = CoreUIObject.getLogger(ProjectGkgUI.class);
    private boolean isQuery=false;
    private boolean isOnLoad=false;
    /**
     * output class constructor
     */
    public ProjectGkgUI() throws Exception
    {
        super();
    }
    public void onLoad() throws Exception {
    	isOnLoad=true;
		setShowDialogOnLoad(true);
		kDTable1.getStyleAttributes().setLocked(true);
    	super.onLoad();
    	isOnLoad=false;
    	this.refresh();
    }
    
    protected Dimension getQueryDialogSize(CustomerQueryPanel[] userPanels) {
    	Dimension size = new Dimension(500, 120);
    	return size;
    }
    private void refresh() throws Exception {
		query();
	}
    
    
    protected boolean initDefaultFilter()
    {
        return false;
    }
    
    protected RptParams getParamsForInit() { 
        return null;
	}
    
    protected CommRptBaseConditionUI getQueryDialogUserPanel() throws Exception {
		return new ProjectGkFilterUI();
	}
    protected ICommRptBase getRemoteInstance() throws BOSException {
		return ProjectGkgFacadeFactory.getRemoteInstance();
	}
    
    protected void query() {
    	if(isOnLoad) return;
    	this.kDTable1.removeColumns();
    	this.kDTable1.removeRows();
		
		tHelper = new TablePreferencesHelper(this);
		initUserConfig();
		 
    }
    
    public void tableDataRequest(KDTDataRequestEvent kdtdatarequestevent) {
		if(isQuery) return;
		isQuery=true;
		Window win = SwingUtilities.getWindowAncestor(this);
        LongTimeDialog dialog = null;
        if(win instanceof Frame){
        	dialog = new LongTimeDialog((Frame)win);
        }else if(win instanceof Dialog){
        	dialog = new LongTimeDialog((Dialog)win);
        }
        if(dialog==null){
        	dialog = new LongTimeDialog(new Frame());
        }
        dialog.setLongTimeTask(new ILongTimeTask() {
            public Object exec()throws Exception{
            	RptParams resultRpt = getRemoteInstance().query(params);
             	return resultRpt;
            }
            public void afterExec(Object result)throws Exception{
            	RptParams rpt = getRemoteInstance().createTempTable(params);
				RptTableHeader header = (RptTableHeader)rpt.getObject("header");
				KDTableUtil.setHeader(header, kDTable1);
				
				RptRowSet rs = (RptRowSet)((RptParams)result).getObject("rowset");
				kDTable1.setRowCount(rs.getRowCount());
				KDTableUtil.insertRows(rs, 0, kDTable1);
            }
        });
        dialog.show();
    	isQuery=false;
	}
    
	protected KDTable getTableForPrintSetting() {
		return kDTable1;
	}

}